<?php
#*********************************************************
#         Author: Huangsheng01 (huangsheng01@snda.com)
#  Last modified: 2010-11-21 11:47:35
#       Filename: helpers/ip_helper.php
#    Description: 按用户IP
#*********************************************************


class ip_helper
{
	static function getonlineip()
	{
		if(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
			$onlineip = getenv('HTTP_X_FORWARDED_FOR');
		} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
			$onlineip = getenv('REMOTE_ADDR');
		} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
			$onlineip = $_SERVER['REMOTE_ADDR'];
		} elseif (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
			$onlineip = getenv('HTTP_CLIENT_IP');
		}
		preg_match("/[\d\.]{7,15}/", $onlineip, $onlineipmatches);
		return $onlineipmatches[0] ? $onlineipmatches[0] : 'unknown';
	}

	static function is_company()
	{
		$ip_of_company	= array(
			'61.172.247.99',
			'61.172.247.98',
			'61.172.247.97',
			'61.172.241.100',
			'203.110.174.186',
			'210.51.28.220',
			'203.110.174.186',
			'210.51.28.229',
			'61.172.241.99',
			'61.172.241.100',
			'61.172.241.120',
			'127.0.0.1'
		);
		$ip	= self::getonlineip();
		if (in_array($ip, $ip_of_company))
			return true;
		elseif (preg_match('/10\.1/', $ip))
			return true;
		else
			return false;
	}

}
